# _*_ coding:utf-8 _*_
# @File  : encryptor.py
# @Time  : 2020-09-05 0:35
# @Author: zizle
import random
import time
from datetime import datetime
from hashlib import md5
""" 生成，加密 """


def generate_chart_option_filepath(user_id: int):
    """ 生成图形配置的json文件相对路径 """
    hash_handler = md5(str(user_id).encode("utf-8"))
    hash_handler.update(str(time.time()).encode("utf-8"))
    today = datetime.today()
    filepath = "{}/{}/{}/{}.json".format(user_id, today.strftime("%Y"), today.strftime("%m"), hash_handler.hexdigest())
    return filepath


def generate_random_filename():
    hash_handler = md5(str(time.time()).encode("utf-8"))
    return hash_handler.hexdigest()


def generate_random_string(isdigit=False, isalpha=False, isupper=True, alluper=False, ismix=True, length=6):
    char1 = '0123456789'
    char21 = 'abcdefghijklmnopqrstuvwxyz'
    char22 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    char3 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    char4 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
    char5 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_+=-*/~'

    c = char5
    if not ismix:
        c = char4
    if isalpha:
        c = char3
        if not isupper:
            c = char21
        if alluper:
            c = char22

    if isdigit:
        c = char1
    return ''.join([c[random.randint(0, len(c)-1)] for _ in range(length)])


# if __name__ == '__main__':
#     print(generate_random_string(length=64))
